//
//  ZYCSourceWisdonCenterViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/18.
//

#import "ZYCSourceWisdonCenterViewController.h"
#import "ZYCSourceWisdonCenterCell.h"
#import "ZYCWisdomSourceFolderViewController.h"
#import "ZYCDownloadManagerViewController.h"

@interface ZYCSourceWisdonCenterViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, strong) UIButton *rightButton;
@end

@implementation ZYCSourceWisdonCenterViewController

#pragma mark - 生命周期函数
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"资源中心";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
    [self.view addSubview:self.tableView];
}


#pragma mark - 点击事件
- (void)clickRightAction:(UIButton *)sender{
    ZYCDownloadManagerViewController *vc = [[ZYCDownloadManagerViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
                          

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCSourceWisdonCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCSourceWisdonCenterCell class]) forIndexPath:indexPath];
    cell.titleString = self.dataSource[indexPath.section];
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 17.0f;
    }
    return 10.0f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ZYCWisdomSourceFolderViewController *vc = [[ZYCWisdomSourceFolderViewController alloc] init];
    vc.titleString = self.dataSource[indexPath.section];
    if (indexPath.section == 0) {
        vc.type = ZYCFolderTypePublic;
    }else{
        vc.type = ZYCFolderTypePerson;
    }
    vc.parentFolderId = 0;
    [self.navigationController pushViewController:vc animated:YES];

}

#pragma mark - getters
- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[@"公共文件夹",@"个人文件夹"];
    }
    return _dataSource;
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ZYCSourceWisdonCenterCell class] forCellReuseIdentifier:NSStringFromClass([ZYCSourceWisdonCenterCell class])];
    }
    return _tableView;
}


- (UIButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [[UIButton alloc] init];
        [_rightButton setTitle:@"下载管理" forState:UIControlStateNormal];
        [_rightButton setTitleColor:HEX_RGB(@"FFFFFF") forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(clickRightAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightButton;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
